#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
	int add,del;
}a[35];
char x;
int n,m,minn=1e9+5;
string str;
bool hw(string x)
{
	for(int i=0,j=x.size()-1;i<j;i++,j--)
		if(x[i]!=x[j])return false;
	return true;
}
/*int work(string x,int y)
{
	int res=0;
	if(y<n-y-1)
	{
		for(int i=y+1;i<x.size();i++)
		{
			
		}
	}
}*/
int main()
{
	freopen("hw.in","r",stdin);
	freopen("hw.out","w",stdout);
	cin>>n>>m>>str;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		cin>>a[x-'a'+1].add>>a[x-'a'+1].del;
	}
	/*if(hw(str))
	{
		cout<<0;
		return 0;
	}
	for(int i=0;i<m;i++)
		minn=(minn,work(hw,i));*/
	if(m==2)
	{
		if(str[0]!=str[1])
			cout<<min(min(a[str[0]-'a'+1].add,a[str[1]-'a'+1].add),min(a[str[0]-'a'+1].del,a[str[1]-'a'+1].del));
		else cout<<0;
	}
	else if(m==3)
	{
		if(str[0]==str[1]&&str[1]!=str[2])
			cout<<min(min(a[str[0]-'a'+1].add*2,a[str[2]-'a'+1].add),min(a[str[0]-'a'+1].del*2,a[str[2]-'a'+1].del));
		if(str[1]==str[2]&&str[1]!=str[0])
			cout<<min(min(a[str[0]-'a'+1].add,a[str[1]-'a'+1].add*2),min(a[str[0]-'a'+1].del,a[str[1]-'a'+1].del*2));
		if(str[0]==str[2])
			cout<<0;
		if(str[0]!=str[1]&&str[0]!=str[2]&&str[1]!=str[2])
			cout<<min(min(a[str[1]-'a'+1].add+a[str[2]-'a'+1].add,min(a[str[0]-'a'+1].add+a[str[2]-'a'+1].add,a[str[0]-'a'+1].add+a[str[1]-'a'+1].add)),min(a[str[1]-'a'+1].del+a[str[2]-'a'+1].del,min(a[str[0]-'a'+1].del+a[str[2]-'a'+1].del,a[str[0]-'a'+1].del+a[str[1]-'a'+1].del)));
	}
	else if(hw(str))
		cout<<0;
	fclose(stdin);
	fclose(stdout);
	return 0;
}
